package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.model.Zyb;

import imp.Zydao;

public class ZydaoImp implements Zydao{
	public Zyb getOneZy(Integer zyId){
		try{
			Session session=org.factory.HibernateSessionFactory.getSession();
			Transaction ts=session.beginTransaction();
			Query query =session.createQuery("from Zyb where id=?");
			query.setParameter(0, zyId);
			query.setMaxResults(1);
			Zyb zy=(Zyb)query.uniqueResult();
			ts.commit();
			session.close();
			return zy;
			
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public List getAll(){
		try{
			Session session=org.factory.HibernateSessionFactory.getSession();
			Transaction ts=session.beginTransaction();
			List list=session.createQuery("from Zyb").list();
			ts.commit();
			session.close();
			return list;
			
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

}
